package com.code.zjm.demo.ui;

import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TimePicker;

import java.util.Locale;

/**
 * Created by ZJM on 2017/3/4.
 */

public class AtyShowDatePicker extends AppCompatActivity {
    private Button btDatePicker, btnTimePicker;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_datepicker);
        btDatePicker = (Button) findViewById(R.id.btDatePicker);
        btnTimePicker = (Button) findViewById(R.id.btnTimePicker);

        //日期选择
        btDatePicker.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new DatePickerDialog(AtyShowDatePicker.this, new DatePickerDialog.OnDateSetListener() {
                    @Override
                    public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
                        btDatePicker.setText(String.format(Locale.CHINA, "%d:%d:%d", year, month, dayOfMonth));
                    }
                }, 2016, 3, 4).show();
            }
        });

        //时间选择
        btnTimePicker.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new TimePickerDialog(AtyShowDatePicker.this, new TimePickerDialog.OnTimeSetListener() {
                    @Override
                    public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                        btnTimePicker.setText(String.format(Locale.CHINA, "%d:%d", hourOfDay, minute));
                    }
                }, 01, 45, true).show();
            }
        });

    }
}
